﻿using System;
namespace LeRenard.ScriptWars.Model.GridSystem
{
    public class RandomGridInitializer<TValue> : DefaultGridInitializer<TValue>
        where TValue : class
    {
        /// <summary>
        /// Function that generates a random value.
        /// </summary>
        public Func<TValue> RandomValueGenerator { get { return _randomValueGenerator; } }
        private readonly Func<TValue> _randomValueGenerator;

        /// <summary>
        /// Creates a new <see cref="RandomGridInitializer"/> object.
        /// </summary>
        /// <param name="randomValueGenerator"></param>
        public RandomGridInitializer(Func<TValue> randomValueGenerator)
            : base()
        {
            ThrowIf.Null(() => randomValueGenerator);

            _randomValueGenerator = randomValueGenerator;
        }

        /// <summary>
        /// Generates a value for a <see cref="GridCell"/>.
        /// </summary>        
        public override TValue GenerateValue()
        {
            return RandomValueGenerator();
        }
    }
}
